{extend name=".././view/list.html" /}
{block name="jsset"}
{/block}
{block name="nav"}
<span class="layui-breadcrumb">
	<a href="">考试管理</a>
	<a href="">更多操作</a>
	<a href="">成绩查看</a>
	<a><cite>成绩列表</cite></a>
</span>
{/block}
{block name="search"}
<div class="layui-form-item">
	<label for="searchval" class="layui-form-label">
		关键字
	</label>
	<div class="layui-input-block">
		<input type="text" id="searchval" name="searchval" autocomplete="off" class="layui-input" placeholder="姓名、考号" placeholder="输入关键字并回车">
	</div>
</div>
<div class="layui-form-item">
	<label for="school_id" class="layui-form-label"><span class="x-red">*</span>学校</label>
	<div class="layui-input-block">
		<select name="school_id" id="school_id" lay-filter="src">
		</select>
	</div>
</div>
<div class="layui-form-item">
	<label for="ruxuenian" class="layui-form-label">
		<span class="x-red">*</span>年级
	</label>
	<div class="layui-input-block">
		<select name="ruxuenian" id="ruxuenian" class="layui-form-label" lay-filter="src">
		</select>
	</div>
</div>
<div class="layui-form-item">
	<label for="banji_id" class="layui-form-label">
		<span class="x-red">*</span>班级
	</label>
	<div class="layui-input-block" id="banji_id">
	</div>
</div>
<input type="hidden" id="kaoshi_id" name="kaoshi_id" value="{$list.kaoshi_id}">
<div class="layui-form-item" style="text-align: right;">
	<button class="layui-btn" lay-filter="searchSubmit" lay-submit="">搜索</button>
</div>
{/block}
{block name="table"}
<table id="tabledemo" lay-filter="mytable" lay-size="sm"></table>
{/block}
{block name="myjs"}
<!-- 表格上面按钮模板 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
    <button class="layui-btn layui-btn-danger" lay-event="dels">
      <i class="iconfont">&#xe69d;</i> 批量删除考号
    </button>
    <button class="layui-btn" lay-event="add">
      <i class="iconfont">&#xe6b9;</i> 添加考号
    </button>
    <button class="layui-btn" lay-event="delcj">
      <i class="iconfont">&#xe69d;</i> 删除成绩
    </button>
    <button class="layui-btn" lay-event="download">
      <i class="layui-icon layui-icon-download-circle"></i> 下载成绩列表
    </button>
    <button class="layui-btn" lay-event="downloadcjtiao">
      <i class="layui-icon layui-icon-download-circle"></i> 下载成绩条
    </button>
  </div>
</script>
<!-- 记录操作按钮模板 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn-xs" lay-event="edit" title="编辑"><i class="layui-icon layui-icon-edit"></i></a>
	<a class="layui-btn-xs" lay-event="detail" title="录入信息"><i class="layui-icon layui-icon-search"></i></a>
  <a class="layui-btn-xs" lay-event="chengji" title="成绩图表"><i class="layui-icon layui-icon-chart-screen"></i></a>
  <a class="layui-btn-xs" lay-event="del" title="删除考号"><i class="layui-icon">&#xe640;</i></a>
</script>
<!-- 表格操作 -->
<script>
// 提交搜索条件后重载表格
layui.use(['table', 'mytable', 'form', 'canyuKaoshi', 'createInput'], function() {
	var table = layui.table,
		mytable = layui.mytable,
		canyu = layui.canyuKaoshi,
		cInput = layui.createInput,
		form = layui.form;

	canyu.schoolSelect('school_id', "{$list.kaoshi_id}");
	canyu.gradeSelect('ruxuenian', "{$list.kaoshi_id}");

	// 设置列
	options.cols = [
		[ //表头
			{ type: 'checkbox', fixed: 'left' },
			{ type: 'numbers', fixed: 'left', title: '序号' },
			{ field: 'school_jiancheng', title: '学校', minWidth: 100, sort: true },
			{ field: "ban_title", title: '班级', minWidth: 120, sort: true },
			{ field: "student_xingming", title: '学生姓名', sort: true, minWidth: 100 },
		]
	];

	var xk = '<?php echo json_encode($list["set"]["subject_id"]);?>';
	xk = eval(decodeURIComponent(xk));
	var tjxm = '<?php echo json_encode($list["tjxm"]);?>';
	tjxm = eval(decodeURIComponent(tjxm));

	$.each(xk, function(index, value) {
		options.cols[0].push({
			field: value.lieming + 'defen',
			title: value.title,
			minWidth: 120,
			sort: true,
			templet: function(d) {
				var str = d[value.lieming + 'defen'];
				if (str == null) {
					str = '';
				}
				return str;
			}
		});
		$.each(tjxm, function(t, val) {
			options.cols[0].push({
				field: value.lieming + val.biaoshi,
				sort: true,
				title: value.title + val.title,
				minWidth: 120,
				templet: function(d) {
					var str = d[value.lieming + val.biaoshi];
					if (str == null) {
						str = '';
					}
					return str;
				}
			});
		})
	});

	options.cols[0].push({ field: 'avg', title: '平均分', minWidth: 100, sort: true });
	options.cols[0].push({ field: 'sum', title: '总分', minWidth: 100, sort: true });
	options.cols[0].push({ field: 'id', title: '操作', toolbar: '#barDemo', minWidth: 135 });
	// 设置每页显示条数
	options.limit = 10;
	options.limits = [10, 15];

	// 获取筛选条件并加载表格
	options.where = form.val("search");
	userTable = table.render(options); //获取数据并渲染

	//表头工具栏事件
	table.on('toolbar(mytable)', function(obj) {
		switch (obj.event) {
			case 'add':
				xadmin.open('添加考号', '/kaohao/index/create/{$list.kaoshi_id}', '550', '400');
				break;
			case 'dels':
				var checkStatus = table.checkStatus('mytable'); //idmytable 即为基础参数 id 对应的值
				mytable.delAll(checkStatus, '/kaohao/index/delete', 'mytable');
				break;
			case 'download':
				xadmin.open('下载成绩列表', '/chengji/index/dwchengji/{$list.kaoshi_id}', '650', '300');
				break;
			case 'downloadcjtiao':
				xadmin.open('下载成绩条', '/chengji/index/dwchengjitiao/{$list.kaoshi_id}', '650', '300');
				break;
			case 'delcj':
				parent.xadmin.add_tab('删除成绩', '/chengji/index/deletecjs/{$list.kaoshi_id}', true);
				break;
		};
	});

	//监听行工具条
	table.on('tool(mytable)', function(obj) {
		var data = obj.data; //获得当前行数据
		var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
		var tr = obj.tr; //获得当前行 tr 的DOM对象
		switch (layEvent) {
			case 'edit': // 编辑
				xadmin.open('编辑考号', '/kaohao/index/edit/' + obj.data.id, '', '', true);
				break;
			case 'detail': // 查看
				xadmin.open(obj.data.student_xingming + ' 成绩录入信息', '/chengji/index/readcjadd/' + obj.data.id, '', '', true);
				break;
			case 'chengji': // 查看
				xadmin.open(obj.data.student_xingming + ' 成绩图表', '/kaohao/index/read/' + obj.data.id, '', '', true);
				break;
			case 'del': // 删除
				mytable.del(obj, "/kaohao/index/delete");
				break;
		};
	});

	// 监听学校下拉菜单
	form.on('select(src)', function(data) {
		data = form.val("search");
		if (data.school_id > 0 && data.ruxuenian > 0) {
			data.auth = {};
			canyu.banjiCheckbox('banji_id', data);
		}
	});

	form.on('checkbox(mycheackbox)', function(data) {
		cInput.checkboxChecked(data);
	});

});

</script>
{/block}
